package com.freeedu.mq01;

import java.util.List;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;

public class Consumer {
	public static void main(String[] args) throws Exception {
		DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("xxoo-consumer-group");
    	consumer.setNamesrvAddr("192.168.2.136:9876");
    	
    	// topic  过滤器 
    	consumer.subscribe("topic01", "*");
    	
    	// 
    	consumer.registerMessageListener(new MessageListenerConcurrently() {
			
			public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
				System.out.println("消费：==========");
				msgs.stream().forEach(m->{
					String s = new String(m.getBody());
					System.out.println(s);
				});
				
				
				// ack  失败了就返回ConsumeConcurrentlyStatus.RECONSUME_LATER
				return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
			}
		});
     
	}
}
